var path;
function initPath(ctx){
	path = ctx;
}
function ajaxRequest(url,asy,data,type){
	var data="";
	 $.ajax({
         type: type,
         async:asy,
         url: path+url,
         data: JSON.stringify(data),
         contentType:"application/json;charset=UTF-8", 
         dataType:"json",
         success: function(dat){    	            	 
         data = dat;
                  }
     }); 
	 return data;
}
//初始化上传文件控件
function initFileInput(id,initImg){
	if(initImg==undefined||initImg==""){
		$("#"+id+"").fileinput({
	        previewFileType: "image", 
	        browseClass: "btn btn-success",
	        browseLabel: "请选择",
	        browseIcon: "<i class=\"glyphicon glyphicon-picture\"></i> ",
	        removeClass: "btn btn-danger",
	        removeLabel: "删除",
	        removeIcon: "<i class=\"glyphicon glyphicon-trash\"></i> ",
	        uploadClass: "btn btn-info",
	        uploadLabel: "上传",
	        uploadIcon: "<i class=\"glyphicon glyphicon-upload\"></i> ", 
	        uploadUrl: path+"pcphoto/pcphotoImg",
	        allowedFileExtensions: ["jpg", "png", "gif"],	 
	        maxFileCount: 5,
	        width:200,
	        height:200,
	        resizeImage: true
	        	}).on('filepreupload', function(data) {
	                console.log(data);
	        	    $('#kv-success-box').html('');
	        	}).on('fileuploaded', function(event, data) {
	        		  console.log(data);
	        		 if(data.response.code==0){
	        				$("#imgId").val(data.response.data.purl);       
	        		 }else{
	        			 var txt=data.response.msg;
					  window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.info);
	        			 
	        		 }
	        	    $('#kv-success-box').append(data.response.link);
	        	    $('#kv-success-modal').modal('show');
	        	}).on('fileclear', function(event, key) {  
	        	       alert("图片被移除");
	        	      $("#imgId").val(null); 
	        	});
	}else{
		$("#"+id+"").fileinput({
	        previewFileType: "image", 
	        browseClass: "btn btn-success",
	        browseLabel: "请选择",
	        browseIcon: "<i class=\"glyphicon glyphicon-picture\"></i> ",
	        removeClass: "btn btn-danger",
	        removeLabel: "删除",
	        removeIcon: "<i class=\"glyphicon glyphicon-trash\"></i> ",
	        uploadClass: "btn btn-info",
	        uploadLabel: "上传",
	        uploadIcon: "<i class=\"glyphicon glyphicon-upload\"></i> ", 
	        uploadUrl: path+"pcphoto/pcphotoImg",
	        allowedFileExtensions: ["jpg", "png", "gif"],	 
	        maxFileCount: 5,
	        initialPreview: [
	            '<img src="'+initImg+'"  id="img"  class="file-preview-image"  width="256px" height="160px" />',
	        ],
	        resizeImage: true
	        	}).on('filepreupload', function(data) {
	                console.log(data);
	        	    $('#kv-success-box').html('');
	        	}).on('fileuploaded', function(event, data) {
	        		  console.log(data);
	        		 if(data.response.code==0){
	        				$("#imgId").val(data.response.data.purl);       
	        		 }else{
	        			 var txt=data.response.msg;
					  window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.info);
	        			 
	        		 }
	        	    $('#kv-success-box').append(data.response.link);
	        	    $('#kv-success-modal').modal('show');
	        	}).on('fileclear', function(event, key) {  
	        	       alert("图片被移除");
	        	      $("#imgId").val(null); 
	        	});
	}
}
   //时间格式化
	function timeStamptoString(time){
	    var datetime = new Date();
	    datetime.setTime(time);
	    var year = datetime.getFullYear();
	    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
	    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
	    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
	    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
	    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
	    return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second
	}
	//获取表单对象
	 var serialize = function(form){
	      var $form = (typeof(form)=="string" ? $("#"+form) : form);
	      var dataArray =  $form.serializeArray();
	     var result={};
	      $(dataArray).each(function(){
	          //如果在结果对象中存在这个值，那么就说明是多选的情形。
	          if(result[this.name]){
	              //多选的情形，值是数组，直接push
	              result[this.name].push(this.value);
	          }else{
	              //获取当前表单控件元素
	              var element = $form.find("[name='"+ this.name +"']")[0];
	              //获取当前控件类型
	              var type = ( element.type || element.nodeName ).toLowerCase();
	              //如果控件类型为多选那么值就是数组形式，否则就是单值形式。
	              result[this.name] = (/^(select-multiple|checkbox)$/i).test(type) ? [this.value] : this.value;
	          }
	      });
	      return result;
	  };